import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  UpdateDateColumn,
  OneToMany,
} from 'typeorm';
import { Chapter } from './chapter.entity';

@Entity('novels')
export class Novel {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  title: string;

  @Column()
  author: string;

  @Column({ nullable: true, type: 'text' })
  cover: string;

  @Column({ nullable: true, type: 'text' })
  description: string;

  @Column()
  source: string; // 'qidian' | 'fanqie'

  @Column({ length: 2000 })
  sourceUrl: string;

  @Column({ nullable: true })
  category: string;

  @Column({ nullable: true })
  wordCount: string; // 字数，如"100.1万字"

  @Column({ default: 0 })
  status: number; // 0: 连载中, 1: 已完结

  @Column({ default: 0 })
  chapterCount: number;

  @Column({ default: 0 })
  shareCount: number;

  @CreateDateColumn()
  createdAt: Date;

  @UpdateDateColumn()
  updatedAt: Date;

  @OneToMany(() => Chapter, (chapter) => chapter.novel)
  chapters: Chapter[];
}
